<!DOCTYPE html>
<html lang="zh">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>手机端模板</title>
    <link rel="stylesheet" href="{{ url_for('static', filename='css/all.min.css') }}">
    <style>
        body, html {
            height: 100%;
            margin: 0;
            padding: 0;
            width: 100%;
            font-family: Arial, sans-serif;
        }
        .content-wrapper {
            display: flex;
            flex-direction: column;
            height: 100%;
            width: 100%;
            margin: 0;
            padding: 0;
        }
        header {
            position: fixed;
            top: 0;
            width: 100%;
            z-index: 1000;
            background-color: #333;
            color: #fff;
            padding: 2px 0;
            height: 5%;
            text-align: center;
            line-height: 50px;
        }
        header h1 {
            font-size: 1.5em;
            margin: 0;
        }
       .content {
            margin-top: 50px;
            margin-bottom: 120px;
        }

        iframe {
            width: 100%;
            height: calc(100vh - 120px);
            border: 0;
        }

        footer {
            position: fixed;
            bottom: 0;
            width: 100%;
            background-color: #333;
            color: #fff;
            display: flex;
            justify-content: space-between;
            padding: 10px;
            box-shadow: 0 -2px 6px rgba(0, 0, 0, 0.1);
        }
        nav {
            display: flex;
            justify-content: space-between;
            align-items: center;
            width: 100%;
        }
        nav a {
            text-decoration: none;
            color: #fff;
            display: flex;
            flex-direction: column;
            align-items: center;
            text-align: center;
            flex: 1;
            padding: 5px;
        }
        nav a i {
            font-size: 1.5em;
            margin-bottom: 5px;
        }
        nav a.active {
            background-color: #555;
            color: #ADD8E6;
        }
        @media (max-width: 480px) {
            nav a {
                flex-direction: row;
                justify-content: center;
            }
            nav a i {
                margin-right: 5px;
                margin-bottom: 0;
            }
            nav a span {
                font-size: 0.8em;
            }

            .content {
            margin-top: 50px;
            margin-bottom: 100px;
            }

            iframe {
            width: 100%;
            height: calc(100vh - 100px);
            border: 0;
            }
        }
        .user-info {
            position: absolute;
            right: 10px;
            top: 50%;
            transform: translateY(-50%);
            color: #fff;
            text-decoration: none;
        }
        .user-info img {
            width: 40px;
            height: 40px;
            border-radius: 50%;
            vertical-align: middle;
            margin-right: 5px;
        }
        .user-info span {
            vertical-align: middle;
        }
        .avatar-icon {
            display: none;
            vertical-align: middle;
            margin-right: 5px;
        }

      .back-button {
          position: absolute;
          left: 10px;
          top: 50%;
          transform: translateY(-50%);
          color: #fff;
          text-decoration: none;
        }

      .back-button i {
          display: none;
        }

      .back-button.without-text i {
          display: inline-block;
        }

    </style>
</head>
<body>
<div class="content-wrapper">
    <header>
        <a href="javascript:history.back()" class="back-button without-text">
            <i class="fas fa-arrow-left"></i>
            <span>返回</span>
        </a>
        <h1>JhERP</h1>
        <a href="#" id="logout-btn" class="user-info">
            <img src="path_to_your_avatar.jpg" alt="User Avatar"
                 onerror="this.onerror=null; this.style.display='none'; this.nextElementSibling.style.display='inline-block';">
            <span class="fas fa-user fa-2x avatar-icon" style="display: none;"></span>
            <span>注销</span>
        </a>
    </header>
    <div class="content">
        <iframe id="contentFrame" src="/product_list" frameborder="0"></iframe>
    </div>
</div>
<footer>
    <nav>
        <a onclick="loadContent('/list_customer')" class="customer-link">
            <i class="fas fa-user"></i>
            <span>客户</span>
        </a>
        <a onclick="loadContent('/product_list')" class="products-link">
            <i class="fas fa-box"></i>
            <span>产品</span>
        </a>
        <a href="#home" class="home-link">
            <i class="fas fa-home"></i>
            <span>首页</span>
        </a>
        <a onclick="loadContent('/warehousing_entry_list')" class="invoices-link">
            <i class="fas fa-file-invoice"></i>
            <span>单据</span>
        </a>
        <a onclick="loadContent('/inventory')" class="warehouse-link">
            <i class="fas fa-warehouse"></i>
            <span>仓库</span>
        </a>
    </nav>
</footer>
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script>
    // 使用 jQuery 处理点击事件
    $('nav a').click(function(e) {
        e.preventDefault();
        var target = $(this).attr('href');
        // 注意：由于我们使用的是iframe，这里隐藏和显示操作不再适用
        // $('.content > div').hide();
        // $(target).show();
        $('nav a').removeClass('active');
        $(this).addClass('active');
        loadContent($(this).attr('onclick').match(/loadContent\('([^']+)'\)/)[1]);
    });

    function loadContent(url) {
        document.getElementById('contentFrame').src = url;
    }

        // 获取注销按钮
    var logoutBtn = document.getElementById("logout-btn");
        // 给注销按钮添加点击事件
    logoutBtn.addEventListener("click", function(){
        // 发送POST请求到服务器以注销用户
        fetch('/logout', { method: 'POST' })
            .then(response => {
                if (response.redirected) {
                    // 重定向到登录页面
                    window.location.href = response.url;
                }
            })
            .catch(error => {
                console.error('Error:', error);
            });
    });

    let timeout;
</script>
</body>
</html>